#include "aabb.h"

AABB::AABB(Vectorf *aMin, Vectorf *aMax) : min(aMin), max(aMax)
{
    type=1;
    translation= new Vectorf(0,0,0);
}

AABB::AABB(Vectorf *aMin, Vectorf *aMax, Vectorf *aTranslation) : min(aMin), max(aMax)
{
    type=1;
    translation=aTranslation;
}

int AABB::Collide(Enveloppe * ab)
{
    if(ab->type==1)         // AABB
    {
        printf(" lolol \n");
        AABB * b= (AABB *)(ab);
        printf("LOlilol \n");

        Vectorf * bMin= new Vectorf(*b->min);
        *bMin=*bMin+*b->translation;
        Vectorf * bMax= new Vectorf(*b->max);
        *bMax=*bMax+*b->translation;

        Vectorf * aMax = new Vectorf(*max);
        *aMax= *aMax+*translation;

        Vectorf * aMin = new Vectorf(*min);
        *aMin= *aMin+*translation;

        printf("LOlilol \n");

        if(bMin->x()<aMax->x()&& aMin->x()<bMax->x())
        {
            if(bMin->y()>aMax->y())
            {
                if(bMin->z()>aMax->z())
                {
                    return 1;
                }
            }
        }
        return 0;

    }
    else if(ab->type==2)    // Sphere
    {
        BoundingSphere * b= (BoundingSphere *)(ab);

        if((*translation- * b->translation).Norme()>b->rayon)
        {
            return 1;
        }
        return 0;
    }
    else if(ab->type==3)    // Mesh
    {
        return 0;
    }
}

int AABB::SegmentAABBCollisionDetection(Vectorf *u, Vectorf *vertex)
{
    //Vectorf::IntersectionPlan( u, lineVertex, normalPlan, planeVertex);
}
